import pymysql

connect = pymysql.Connect(  # 连接数据库
    host='127.0.0.1',
    port=3306,
    user='root',
    passwd='',
    db='taobao', # database
    charset='utf8' # 字符集
)

cursor = connect.cursor()  # 获取游标

try:
    sql = "insert into user (uid, uname, upassword) values(5,'good', '123');"  # 获取所有数据
    cursor.execute(sql)

    sql = "insert into user (uid, uname, upassword) values(6,'good', '123');"  # 获取所有数据
    cursor.execute(sql)

    sql = "insert into user (uid, uname, upassword) values(6,'good', '123');"  # 获取所有数据
    cursor.execute(sql)

except Exception as me:
    print(me)
    connect.rollback()
else:
    connect.commit()  # 提交事务
finally:
    cursor.close()  # 关闭游标
    connect.close()  # 关闭连接


